Note: This software is a beta version and must not be used in game products.
The socket library provides the access to the internet via the Nintendo GameCube broadband adapter. The socket library API has many resemblance to Berkeley sockets which are the de facto standard programming interface for networking. Programs written to Berkeley sockets interface can be ported to GameCube very easily.
The following table illustrates the correspondence of the GameCube socket APIs and Berkeley sockets.
| Berkeley socket API | GameCube Socket API |
accept() |
SOAccept() |
bind() |
SOBind() |
close() |
SOClose() |
connect() |
SOConnect() |
getpeername() |
SOGetPeerName() |
getsockname() |
SOGetSockName() |
getsockopt() |
SOGetSockOpt() |
htonl() |
SOHtoNl()
SONtoHl() |
inet_aton() |
SOInetAtoN() |
inet_ntoa() |
SOInetNtoA() |
inet_ntop() |
SOInetNtoP() |
inet_pton() |
SOInetPtoN() |
listen() |
SOListen() |
poll() |
SOPoll() |
recv() |
SORecv() |
send() |
SOSend() |
shutdown() |
SOShutdown() |
socket() |
SOSocket() |
gethostbyaddr() |
SOGetHostByAddr() |
gethostbyname() |
SOGetHostByName() |
freeaddrinfo() |
SOFreeAddrInfo() |
getaddrinfo() |
SOGetAddrInfo() |
getnameinfo() |
SOGetNameInfo() |
The GCN socket API is primarily different from Berkeley sockets in the following points:
SO" prefix.
(e.g., SOClose(),
SOHostEnt, SO_PF_INET)
SOSockAddrIn) must be set in the
len field of the structure. The GCN socket functions do not take the
length of the socket address structure via a function argument.Internally, the socket library is implemented in the following four layers:
| Socket API | ||
|
||
| IP API | ||
| Network interface API |
Low level access methods to the network interface and to the IP routing table have not been well standardized. Therefore, the GameCube socket library lets the program directly access to the following IP APIs to get the current network interface configuration and to modify the IP routing table.
| IP API | Description |
IPGetLinkState |
Determines whether the network interface is up. |
IPGetMacAddr |
Gets the MAC address of the interface. |
IPGetMtu |
Gets the MTU of the interface. |
IPGetAddr |
Gets the primary internet address of the interface. |
IPGetAlias |
Gets the alias internet address of the interface. |
IPGetBroadcastAddr |
Gets the broadcast address of the interface. |
IPGetGateway |
Gets the default gateway address of the interface. |
IPGetNetmask |
Gets the subnet mask of the interface. |
IPClearConfigError |
Clears the host configuration error code. |
IPGetConfigError |
Gets the host configuration error code. |
IPSetConfigError |
Sets the host configuration error code. |
IPInitRoute |
Initializes the IP routing table. |
IPAddRoute |
Adds the specified data to the routing table. |
IPRemoveRoute |
Removes the specified route from the routing table. |
IPRefreshRoute |
Refreshes the routing table using the base network interface configuration. |
IPClearInterfaceStat |
Clears the interface statistics. |
IPGetInterfaceStat |
Gets the interface statistics. |
PPPGetMessage |
Gets the PAP/CHAP response message. |
The socket library currently reserves the following prefixes and an application program should not define functions that begin with theses names:
| Prefix | Description |
ARP |
address resolution protocol |
DHCP |
dynamic host configuration protocol |
DNS |
domain name system |
ICMP |
internet control message protocol |
IF |
interface |
IP |
internet protocol |
SO |
socket |
TCP |
transmission control protocol |
UDP |
user datagram protocol |
To use the socket library, a program must be linked with ip[D].a
and eth[D].a. ip[D].a implements the internet protocol
stack. eth[D].a implements the low-level broadband adapter
interface.
In a program source code, the following header file must be included:
#include <dolphin/socket.h>
The program must first initialize the socket library with
SOInit(). And then the program can configure the
network interface with
SOStartup().
Note: It is strongly recommended that the program
checks the link status of the broadband adapter with IPGetLinkState()
before configuring the network interface.
There are three ways to configure the network interface.
To configure the network interface via DHCP, initialize the
SOConfig{} structure as shown below. The SO_FLAG_DHCP
flag set in the flag field sets the library to configure the
interface using DHCP.
|
To configure the network interface via PPPoE, initialize the
SOConfig{} structure as shown below. The SO_FLAG_PPPoE
flag set in the flag field sets the library to configure the
interface using PPPoE. The peerid and passwd fields are used if the access
concentrator requires user authentication.
Note: The current implementation supports only PAP and CHAP for user authentication method.
|
If neither SO_FLAG_DHCP nor SO_FLAG_PPPoE flag is
set in the flag field, the interface is configured manually using
addr, netmask and router fields.
The host configuration via DHCP or PPPoE can fail from various reasons (DHCP
server does not exist, given peerid and passwd is not correct, etc.). If the
configuration is failed, a configuration error code is set which can be get with
IPGetConfigError(). Once the program calls
SOStartup(), it should call IPGetConfigError()
repeatedly to verify the network configuration is in normal operation. Once the
host configuration is completed,
SOGetHostID() returns a non-zero IP
address. It can take up to a minute until the host is configured via DHCP or
PPPoE.
Dynamically configured host settings can be queried with
IPGetAddr() and other IP interface
functions.
Note: Even if the network interface is not configured by any means, it can still broadcast and receive UDP datagrams.
Note: Without a broadband adapter, sockets bound to the loopback address can be used.
Up to two DNS server addresses can be specified with SOStartup()
or SOSetResolver(). If DNS server addresses are obtained
via DHCP or PPPoE, then the assigned server addresses can be
retrieved with SOGetResolver(). To look up the host entry, use
SOGetHostByAddr() or
SOGetHostByName() functions.
Once the program no longer needs access to the network, it must shutdown the
network interface with
SOCleanup().
SOCleanup() releases the internet resources
including the IP address assigned from the DHCP server, the PPP session opened
with the access concentrator, etc.
A host network connection can be compulsory terminated if the lease time of the IP
address assigned from the DHCP server expires, the remote PPPoE access
concentrator terminates the current PPP session or the network address collision
is detected. The program may check the cause of the error with
IPGetConfigError(). If a compulsory
termination of the network connection is detected, the
program should immediately shutdown the network interface with
SOCleanup().
Currently the socket library supports TCP and UDP. To use TCP, specify
SO_SOCK_STREAM with SOSocket().
To use UDP, specify SO_SOCK_DGRAM with SOSocket().
The programming using transport protocols is basically same as the standard socket network programming. Please refer the popular text books for the socket network programming in general.
This program shows how to configure the host with SOStartup()
using DHCP.
This program shows hot to configure the host with SOStartup()
using PPPoE.
This program shows how to look up domain name system (DNS) to get the host name from the IP address and vice versa.
This program is a trivial web server implementation. The contents under the 'www' folder in the disc can be accessed with the web browser.
This program shows how to load a network configuration file from a memory card and how to call Network Setup Screen.
The current socket library implementation supports the following RFCs:
| RFC | Protocol | Description |
| 768 | UDP | User Datagram Protocol |
| 777 | ICMP | Internet Control Message Protocol |
| 791 | IP | Internet Protocol |
| 793 | TCP | Transmission Control Protocol |
| 826 | ARP | An Ethernet Address Resolution Protocol |
| 1034, 1035 | DNS | Domain Name System (stub only) |
| 1332 | IPCP | The PPP Internet Protocol Control Protocol |
| 1334 | PAP | PPP Password Authentication Protocol |
| 1661 | PPP | The Point-to-Point Protocol |
| 1994 | CHAP | PPP Challenge Handshake Authentication Protocol |
| 2018 | TCP | Selective Acknowledgment (SACK) |
| 2131, 2132 | DHCP | Dynamic Host Configuration Protocol |
| 2516 | PPPoE | PPP Over Ethernet |
| 2581 | TCP | Slow start, Congestion Avoidance, Fast Retransmit, Fast Recovery, Delayed ACK |
| 3021 | IP | Using 31-Bit Prefixes on IPv4 Point-to-Point Links |
Note: The GameCube socket library employs Berkeley interpretation for the TCP urgent pointer: The TCP urgent pointer points to the byte next to the urgent byte.
Note: The fast retransmit algorithm is activated only when the SACK option is used between two end points in the GameCube socket implementation. Also the GameCube socket implementation uses the FACK congestion control algorithm instead of the fast recovery algorithm.
RFC 1122 defines the requirements for Internet host software. The current implementation does not implement the following required "MUST" items and thus it is not RFC 1122 compliant. Practically these items are not really important for most network applications of these days as packets with source route options are often simply discarded by routers for security reasons.
| Layer | Feature | Description |
| IP | Source Route Option | To be available in the future release |
| UDP | Pass received IP options to application layer | To be available in the future release |
| TCP | Source Route Option | To be available in the future release |
RFC 2525 catalogs a number of known TCP implementation problems. The GameCube socket implementation is adhering to this document for the stability of the global Internet. "SHOULD" items in RFC 1122 that are pointed in RFC 2525 are also implemented in addition to the "MUST" items.